/*
 * TransiCast / Qt
 * (c) 2012 Joachim Pfeiffer
 * Please refer to http://code.google.com/p/transitacst for more information
 */
#include <time.h>
#include <stdio.h>
#include <math.h>

#include "utilities.hpp"

#define PI 3.14159265

Utilities::Utilities()
{

}

std::string Utilities::createAppKey()
{
    return "null"; // Not the real code
}

double deg2rad(double deg)
{
    return deg * PI / 180.0;
}
double rad2deg(double rad)
{
    return rad * 180.0 / PI;
}

double Utilities::distance(double lat1, double lon1, double lat2, double lon2, char unit) {
    double theta = lon1 - lon2;
    double dist = sin(deg2rad(lat1)) * sin(deg2rad(lat2)) + cos(deg2rad(lat1)) * cos(deg2rad(lat2)) * cos(deg2rad(theta));
    dist = acos(dist);
    dist = rad2deg(dist);
    dist = dist * 60 * 1.1515;
    if (unit == 'K')
        dist = dist * 1.609344;
    else
        if (unit == 'N')
            dist = dist * 0.8684;
    return dist;
}
